package com.outdoor.server.controller.admin;

import com.outdoor.common.result.PageResult;
import com.outdoor.common.result.Result;
import com.outdoor.pojo.dto.EventPageQueryDTO;
import com.outdoor.pojo.dto.EventPublishDTO;
import com.outdoor.pojo.entity.Event;
import com.outdoor.pojo.vo.EventVO;
import com.outdoor.server.service.EventService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/event")
@Slf4j
public class EventController {

    @Autowired
    private EventService eventService;

    /**
     * 分页查询活动列表
     * @param eventPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> page(EventPageQueryDTO eventPageQueryDTO) {
        log.info("活动分页查询条件:{}", eventPageQueryDTO);
        PageResult pageResult = eventService.page(eventPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据id查询活动详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<EventVO> getById(@PathVariable Long id) {
        log.info("活动id:{}", id);
        EventVO eventVO = eventService.getById(id);
        return Result.success(eventVO);
    }
    /**
     * 新增活动
     * @param event
     * @return
     */
    @PostMapping()
    public Result add(@RequestBody Event event) {
        log.info("新增活动:{}", event);
        eventService.add(event);
        return Result.success();
    }

    /**
     * 删除活动
     * @param id
     * @return
     */
    @DeleteMapping()
    public Result delete(Long id) {
        log.info("删除活动id:{}", id);
        eventService.delete(id);
        return Result.success();
    }


    /**
     * 发布活动
     * @param id
     * @return
     */
    @PutMapping("/publish/{id}")
    public Result publish(@PathVariable Long id) {
        log.info("发布活动id:{}", id);
        eventService.publish(id);
        return Result.success();
    }

    /**
     * 取消活动
     * @param id
     * @return
     */
    @PutMapping("/cancel/{id}")
    public Result cancel(@PathVariable Long id) {
        log.info("取消活动id:{}", id);
        eventService.cancel(id);
        return Result.success();
    }
}
